﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;

namespace DAO
{
    public class StaffDAO
    {
        BMS_DatabaseEntities context = new BMS_DatabaseEntities();

        /// <summary>
        /// Lay tat ca danh sach sale
        /// </summary>
        public List<StaffEntity> LoadStaff()
        {
            var query = from s in context.STAFF_INFO
                        select new StaffEntity
                        {
                            StaffCode = s.STAFF_CODE,
                            StaffName =s.STAFF_NAME,
                            Gender = (int)s.GENDER,
                            VNname=s.FULL_NAME_VN,
                            EngName=s.FULL_NAME_EN,
                            BirthDay = (DateTime)s.BIRTHDAY,
                            Address= s.ADDRESS,
                            Tel=s.TEL,
                            Mail=s.EMAIL,
                            Remark=s.REMARK,
                            Position=s.POSITION,
                        };
            return query.ToList<StaffEntity>();
        }

        /// <summary>
        /// Lay tat ca danh sach sale tru sale name
        /// </summary>
        public List<StaffEntity> LoadStaff(string SaleName)
        {
            var query = from s in context.STAFF_INFO
                        where s.STAFF_NAME != SaleName
                        select new StaffEntity
                        {
                            StaffCode = s.STAFF_CODE,
                            StaffName = s.STAFF_NAME,
                            Gender = (int)s.GENDER,
                            VNname = s.FULL_NAME_VN,
                            EngName = s.FULL_NAME_EN,
                            BirthDay = (DateTime)s.BIRTHDAY,
                            Address = s.ADDRESS,
                            Tel = s.TEL,
                            Mail = s.EMAIL,
                            Remark = s.REMARK,
                            Position = s.POSITION,
                        };
            return query.ToList<StaffEntity>();
        }

        /// <summary>
        /// Lay tat ca thong tin sale
        /// </summary>
        public StaffEntity LoadStaffInfo(string SaleName)
        {
            var query = (from s in context.STAFF_INFO
                        where s.STAFF_NAME == SaleName
                        select s).First();
            StaffEntity staff = new StaffEntity();

            staff.StaffName = query.STAFF_NAME;
            staff.Address = query.ADDRESS;
            staff.Tel = query.TEL;
            staff.Mail = query.EMAIL;
            staff.VNname = query.FULL_NAME_VN;

            return staff;
        }
    }
}
